<?php
// +---------------------------------------------------------------------+
// | ALINEJUN    | [ WE CAN DO IT JUST THINK ]                            |
// +---------------------------------------------------------------------+
// | Licensed   | http://www.apache.org/licenses/LICENSE-2.0 )           |
// +---------------------------------------------------------------------+
// | Author     | Bigotry <3162875@qq.com>                               |
// +---------------------------------------------------------------------+
// | Repository | https://gitee.com/Bigotry/ALINEJUN                      |
// +---------------------------------------------------------------------+

namespace app\index\controller;

use app\common\controller\ControllerBase;
use app\common\model\Collection;
use think\Db;
use think\Hook;

/**
 * 前端模块基类控制器
 */
class IndexBase extends ControllerBase
{
    
    /**
     * 构造方法
     */
    protected  $model ;
    public $city;
    protected $not_model = ['index','login','foods'];
    public function __construct()
    {
        $controller = request()->controller();

        if(!in_array(strtolower($controller),$this->not_model)){
            $model_name = "\app\common\model\\$controller";
            $this->model = new $model_name();
        }
        $city = Db::name('city')->where(['pid'=>0])->select();
        if(!session('city_id')){
            session('city_id',$city[0]['id']);
        }
        // 执行父类构造方法
        parent::__construct();
        $this->assign('city',$city);
        $this->assign('city_id',  session('city_id'));
        // 前台控制器钩子
        Hook::listen('hook_controller_index_base', $this->request);
    }

    /**
     * @param $id
     * @param $type
     * @param $status
     */
    public function collection($id=3,$type=1,$status=1)
    {
        $collection = new Collection();
        $userid = 1;//session('userid');
        if(!$userid){
            return ['code'=>0,'msg'=>'请先登录~'];
        }
        $res = $collection->setCollection($id,$type,$status,$userid);
        return $res;
    }
}
